#ifndef INCOGNITO_BLOG_HH
#define INCOGNITO_BLOG_HH

#include "dhashblockingclient.hh"
#include "incognitoblockingclient.hh"
#include <vector>
class Blog {
	static const unsigned int blockSize;

	public:
		class RootNode {
			private:
				str m_title;			// Title of the blog
				std::vector<bigint> m_articles;	// Article addresses
				RootNode(const RootNode &rn) {};
			public:
				// Default constructor; creates an empty main block
				RootNode():m_title("Title") {};
				
				//Creates a node
				RootNode(str data) { read(data); };
				void read(str data);

				// Returns data to be written into the block
				str write();

				void setTitle(str title) { m_title=title; };
				str getTitle() { return m_title; };

				void addArticle(bigint artid) { m_articles.push_back(artid); }
				bigint getArticleId(int artnum) { return m_articles[artnum]; }


		};

	private:
		bigint			m_rootID;
		RootNode		m_root;
		ptr<IncognitoBlockingClient>	m_ibc;

		Blog() {};
		Blog(const Blog &b) {};
	
	public:
		// Creates new empty blog
		static bigint createNewBlog(ptr<IncognitoBlockingClient> ibc);
		Blog(ptr<IncognitoBlockingClient> ibc, bigint rootid);

		void setTitle(str title) { return m_root.setTitle(title); };
		str getTitle() { return m_root.getTitle(); };
		bigint getRootID() { return m_rootID; };

		void saveRoot();

		bigint addArticle(str title, str content);
		void getArticle(bigint artid, str &title, str &content);
		void getArticle(unsigned int artnum, str &title, str &content) { getArticle(m_root.getArticleId(artnum),title,content); }
};

#endif  /* INCOGNITO_BLOG_HH */
